package com.ice.app.base.authorization.handler;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.iceframework.core.entity.Result;

/**
 * 处理注销成功
 * @author Palo
 *
 */
@Component
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {

    /**Json转化工具*/
    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException{
//		UserSecurtiyDetails userDetails = (UserSecurtiyDetails) authentication.getPrincipal();
    	Result result = Result.newOne().setCode("200").setMsg("Logout succeed");
        response.getWriter().write(objectMapper.writeValueAsString(result));
    }
}